/* eslint-disable */
import $http from '../utils/http.js'
import echarts from 'echarts'
import { Notification } from 'AtElement';

import columnar from '../containers/statistics/report/index/columnar.js'
import drawPic from '../containers/statistics/report/index/pieChart.js'
import trandoubleColumnar from '../containers/statistics/report/index/trandoubleColumnar.js'
import transverseColumnar from '../containers/statistics/report/index/transverseColumnar.js'
// 函数名

const drawBar = 'report/drawBar';
const drawTranBar = 'report/drawTranBar';
const drawPie = 'report/drawPie';
const staticLog = 'report/staticLog'
// 报告文案

// 存储函数名
const gettotalSafe = 'report/gettotalSafe'
const totalattackevent = 'report/totalattackevent'
const totalloadDepth = 'report/totalloadDepth'
const totaltraffic = 'report/totaltraffic'
const totalauditMonitor = 'report/totalauditMonitor'
const totalvulnerability = 'report/totalvulnerability'
const totalitemWarning = 'report/totalitemWarning'
const totalitemlevel = 'report/totalitemlevel'
const totalitemgrade = 'report/totalitemgrade'
const getHEIGHT = 'report/getHEIGHT'

const reportmsg = {  
	state: {
		tableSafetotal : {
			HEIGHT: 'height: 200px',
			total: 0
		},
		tableattackevent : {
			total: 0,
			unit: 0,
			HEIGHT: 'height: 20px'
		},
		tableloadDepth : {
			total1: 0,
			feedback1: 0
		},
		tabletraffic : {
			total1: 0,
			feedback1: 0
		},
		tableauditMonitor : {
			total1: 0,
			feedback1: 0
		},
		tablevulnerability: {
			total1: 0,
			feedback1: 0
		},
		tableSysmsg: {
			HEIGHT: 'height: 1000px',
			systotal: 0
		},
		tableitemWarning: {
			itemWarning:  [
				{
					value: 0
				},
				{
					value: 0
				}
			],
			totalitemWarning: 0
		},
		tableitemlevel: {
			total: 0,
			data: {
				value: [0,0,0,0,0]
			}
		},
		tableitemgrade :{
			total: 0,
			data: [
				{
					value: 0,
				}
			]
		},

	},             
	actions: {
		// 画柱状图 攻击区域分布 脆弱性区域分布 攻击行为检测情况
		[drawBar]({commit}, selecttime){
            $http.post('/api/report/drawBar', 
                                    {'startTime':selecttime.startTime,
                                    'endTime': selecttime.endTime}).then(({ status, msg, data} = {} ) =>{
           if (status === 'success') {
			// 风险事项等级
			let itemlevel = columnar(data.itemlevel)  
            if (document.getElementById('levelStatistics')) {
                let myChart = echarts.init(document.getElementById('levelStatistics'))
                myChart.setOption(itemlevel)
			}
			commit("report/totalitemlevel", data.itemlevel)
          // 风险事项类型分布
          let itemgrade = columnar(data.itemgrade)  
          if (document.getElementById('differentTypesStatistics')) {
              let myChart = echarts.init(document.getElementById('differentTypesStatistics'))
              myChart.setOption(itemgrade)
			  }  
			  commit("report/totalitemgrade", data.itemgrade)   
				} else if(status === 'fail'){
					Notification.error({
					title: '数据获取异常',
					message: msg
					})
				}
			})
		},

		// 画横向柱状图 
		[drawTranBar]({commit}, selecttime){
          $http.post('/api/report/drawtranBar', {'startTime':selecttime.startTime,
                                          'endTime': selecttime.endTime}).then(({ status, msg, data} = {} ) =>{
				if (status === 'success') {
          // 攻击事件
         let attackevent = transverseColumnar(data.attackevent)  
         if (document.getElementById('attacks')) {
            let myChart = echarts.init(document.getElementById('attacks'))
            myChart.setOption(attackevent)
			}
			let attackStatic = {
				total: data.attackevent.total,
				unit: data.attackevent.data.key.length,
				HEIGHT: 'height:'+data.attackevent.data.key.length * 50 + 'px'
			}
		  commit("report/totalattackevent", attackStatic)
          // 载荷深度分析
         let loadDepthAnalysis = trandoubleColumnar(data.loadDepthAnalysis)  
          if (document.getElementById('loadDepthAnalysis')) {
              let myChart = echarts.init(document.getElementById('loadDepthAnalysis'))
              myChart.setOption(loadDepthAnalysis)
			}
			let loaddata = {
				total1: data.loadDepthAnalysis.data.total1,
				feedback1: data.loadDepthAnalysis.data.feedback1,
			}
			commit("report/totalloadDepth", loaddata)
			let HEIGHT = 'height:' + data.loadDepthAnalysis.data.key.length * 70 + 'px'
			let systotal = data.loadDepthAnalysis.data.key.length
			let sysmsg = {
				'HEIGHT': HEIGHT,
                'systotal': systotal
			}
			commit("report/getHEIGHT", sysmsg)
        // 流量监测
        let trafficMonitoring = trandoubleColumnar(data.trafficMonitoring)  
        if (document.getElementById('trafficMonitoring')) {
                let myChart = echarts.init(document.getElementById('trafficMonitoring'))
                myChart.setOption(trafficMonitoring)
			}
			let traffic = {
				total1: data.trafficMonitoring.data.total1,
				feedback1: data.trafficMonitoring.data.feedback1,
			}
		    commit("report/totaltraffic", traffic)
			// 审计监测
            let auditMonitoring = trandoubleColumnar(data.auditMonitoring)  
            if (document.getElementById('auditMonitoring')) {
                let myChart = echarts.init(document.getElementById('auditMonitoring'))
                myChart.setOption(auditMonitoring)
				}
				let auditdata = {
					total1: data.auditMonitoring.data.total1,
					feedback1: data.auditMonitoring.data.feedback1,
				}
				commit("report/totalauditMonitor", auditdata)
            // 脆弱性监测
            let vulnerabilityMonitoring = trandoubleColumnar(data.vulnerabilityMonitoring)  
            if (document.getElementById('vulnerabilityMonitoring')) {
                    let myChart = echarts.init(document.getElementById('vulnerabilityMonitoring'))
                    myChart.setOption(vulnerabilityMonitoring)
			}
			let vulnerdata = {
				total1: data.vulnerabilityMonitoring.data.total1,
				feedback1: data.vulnerabilityMonitoring.data.feedback1,
			}
            commit("report/totalvulnerability", vulnerdata)
				} else if(status === 'fail'){
					Notification.error({
					title: '数据获取异常',
					message: msg
					})
				}
			})
		},
		
		
		// 画饼图 风险预警
		[drawPie]({commit}, selecttime){
            $http.post('/api/report/drawpie', 
                        {'startTime':selecttime.startTime,
                         'endTime': selecttime.endTime}).then(({ status, msg, data} = {} ) =>{
				if (status === 'success') {
                    // 风险预警情况
					let itemWarning = drawPic(data)  
					console.log(itemWarning, '风险预警情况')
					if (document.getElementById('riskWarningStatistics')) {
						let myChart = echarts.init(document.getElementById('riskWarningStatistics'))
						myChart.setOption(itemWarning)
				     }
				 commit("report/totalitemWarning", data)
				} else if(status === 'fail'){
					Notification.error({
					title: '数据获取异常',
					message: msg
					})
				}
			})
		},
		
		// es 查数据
		[staticLog]({commit}, selecttime){
            $http.post('/api/report/staticLog', 
                        {'startTime':selecttime.startTime,
                         'endTime': selecttime.endTime}).then(({ status, msg, data} = {} ) =>{
				if (status === 'success') {
					let HEIGHT = data.total * 50 + 'px'
					let LogStaticdata = {
						'HEIGHT': HEIGHT,
						'total': data.total
					}
					let itemWarning = transverseColumnar(data)  
					if (document.getElementById('logDataStatistics') && data.total != '0px') {
						let myChart = echarts.init(document.getElementById('logDataStatistics'))
						myChart.setOption(itemWarning)
				    }
				 commit("report/gettotalSafe", LogStaticdata)
				} else if(status === 'fail'){
					Notification.error({
					title: '数据获取异常',
					message: msg
					})
				}
			})
		},	
		
	},
	mutations: {
		[gettotalSafe](state, data) {
			state.tableSafetotal = data
		},
		// 网站安全运行情况
		[totalattackevent](state, data) {
			state.tableattackevent = data
		},
		[totalloadDepth](state, data) {
			state.tableloadDepth = data
		},
		// 威胁分布
		[totaltraffic](state, data) {
			state.tabletraffic = data
		},
		// 区域分布
		[totalauditMonitor](state, data) {
			state.tableauditMonitor = data
		},
		// 机构评分
		[totalvulnerability](state, data) {
			state.tablevulnerability = data
		},
		// 网站评分
		[totalitemWarning](state, data) {
			state.tableitemWarning = data
		},
		// 网站评分
		[totalitemlevel](state, data) {
			state.tableitemlevel = data
		},
		// 网站评分排序
		[totalitemgrade](state, data) {
			state.tableitemgrade = data 
		},
		[getHEIGHT](state, data){
			state.tableSysmsg = data 
		}
	}
};

export default reportmsg;